﻿@{
    ViewBag.Title = "文件借阅";
    Layout = "~/Views/Shared/_LayoutBase.cshtml";
}
@section styles{
    <link href="@Url.Content("~/Content/css/common/bootstrap-table/bootstrap-table.min.css")" rel="stylesheet" />
    <link href="@Url.Content("~/Content/css/common/animate/animate.min.css")" rel="stylesheet" />

    <style type="text/css">
        .popover {
            height: 300px;
            width: 600px;
            overflow: hidden auto;
        }

        ul li {
            font-size: 11px;
            border-bottom:1px solid #ccc;
            margin-bottom:5px;
            margin-right:10px;
        }
    </style>
}
<div id="dMain">
    <div class="wrapper wrapper-content animated fadeInRight">
        <div class="ibox" style="margin-bottom: 0px;">
            <div class="ibox-title">
                <h4>文件借阅</h4>
            </div>
            <div class="ibox-content">
                <div id="toolbar">
                    <a class="btn btn-sm btn-success radius" href="/document/borrow/myborrow" style="margin-top: 10px;"><i class="iconfont icon-tianjia"></i>&nbsp; 我的借阅</a>
                    <div class="text-danger" style="font-size: 14px; margin-top: 15px;margin-left: 10px;float:right; "><i class="iconfont icon-tuichiweixuan"></i>&nbsp;提示：双击行可查看该信息的详细！</div>
                </div>
                <table id="DocumentDataTable"></table>
            </div>
        </div>
    </div>
</div>

@section scripts{
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/locale/bootstrap-table-zh-CN.min.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-export.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/tableExport.js")"></script>
    <script src="@Url.Content("~/Content/js/common/bootstrap-table/bootstrap-table-cookie.js")"></script>
    <script src="@Url.Content("~/Content/js/common/from.js")"></script>
    <script src="@Url.Content("~/Content/js/common/Date.js")"></script>
    <script>
    //var tabHeight = 0;
    $(function () {
        $('#DocumentDataTable').bootstrapTable({
            //  height: tabHeight + 50,
            url: '/Document/Borrow/GetDataTableJsonResult',         //请求后台的URL（*）
            method: 'get',                      //请求方式（*）
            //data: $("#dJson").text() != "" ? JSON.parse($("#dJson").text()) : "",
            dataType: "json",
            columns: [
                {
                    title: "标题", field: 'SUBJECT', align: 'center', formatter: function (value, row, index) {
                        //return '<a href="/Document/Send/Details/' + row.DOC_ID + '">' + row.SUBJECT + '</a>';
                        return '<a href="#" onclick="parent.createTab(\'1303\',\'收文明细\',\'/Document/Send/Details/' + row.DOC_ID + '\')">' + row.SUBJECT + '</a>';
                    }
                },
                {
                    title: "文号", field: 'DOC_NUM', align: 'center'
                },
                {
                    title: "发文人", field: 'DRAFT_AUTHOR', align: 'center'
                },
                {
                    title: "发文时间", field: 'CREATE_TIME', align: 'center', formatter: function (value, row, index) {
                        return new Date(value).Format("yyyy-MM-dd hh:mm:ss");
                    }
                },
                {
                    field: '#',
                    title: "操作",
                    align: 'center',
                    valign: 'middle',
                    formatter: function (value, row, index) {
                        var buttons = '<a class="btn btn-info btn-xs btn-outline" onclick="borrow(\'' + row.DOC_ID + '\')"> 申请借阅</a>';
                        if (@((Session["UserInfo"] as user).DEPT_ID) == 1) { //判断如果操作者是管理员，显示借阅记录按钮
                            var borrowsHTML = "<ul style='width:600px;'>";
                            row.official_document_borrows.forEach(function (item, index) {
                                borrowsHTML += "<li>申请人：" + item.PROPOSER_USER_NAME + "&nbsp;";
                                switch (item.STATUS) {
                                    case 0:
                                        borrowsHTML += "<a class='btn btn-info btn-xs btn-outline' onclick='approval(" + item.BORROW_ID + ");'>批示</a>";
                                        break;
                                    case 1:
                                        borrowsHTML += "<strong style='color:red;'>批示未通过</strong>";
                                        break;
                                    case 2:
                                        borrowsHTML += "<strong style='color:green;'>批示已通过</strong>";
                                        break;
                                }
                                borrowsHTML += "<br/>申请时间：" + new Date(item.CREATE_TIME).Format("yyyy-MM-dd hh:mm:ss") + "&nbsp;";
                                //if (item.STATUS == 1 && item.CREATE_USER_NO == "((Session["UserInfo"] as user).USER_NO)") {
                                //    borrowsHTML += "<a class='btn btn-info btn-xs btn-outline' onclick='reBorrow(" + item.BORROW_ID + ");'>继续申请</a>";
                                //}
                                borrowsHTML += "</li>";
                            });
                            borrowsHTML += "</ul>";
                            buttons += '&nbsp;<a class="btn btn-info btn-xs btn-outline" tabindex="0" role="button" data-trigger="focus" data-toggle="popover" data-placement="left" data-html="true" title="借阅记录" data-content="' + borrowsHTML + '">借阅记录</a>'
                        }
                        return buttons;
                    }
                }
            ],
        toolbar: '#toolbar',//工具按钮用哪个容器
        buttonsClass: "sm btn-white",//按钮class
        pageSize: 10,//分页条数
        clickToSelect: false,//设置true 将在点击行时，自动选择单选或复选框
        singleSelect: false,//为true则禁止多选
        cache: false,//是否缓存
        cookie: true,//是否启用cookie
        cookieIdTable: "Document",//cookie键值
        pagination: true,//是否分页
        showColumns: true,//是否显示所有的列
        showRefresh: true,//是否显示刷新按钮
        search: false,//是否启用搜索
        showPaginationSwitch: true,//是否显示分页切换按钮
        showExport: true,//是否启用导出
        striped: false,//是否显示行间隔色
        detailView: false,//是否显示切换视图列
        //detailFormatter: detailFormatter,//卡片视图内容格式化
        onDblClickRow: function (row, obj) { //双击行事件
            // window.top.showFullPage("图像阅读器（" + (row.FileNo) + "）", "/See.aspx?FID=" + row.ID);
            parent.createTab('1303','收文明细','@Url.Action("Details", "Send", new { area = "Document" })/' + row.DOC_ID + '');
        },
        onClickRow: function (row, obj) { //单击行事件
            $(obj).parent().find("tr").removeClass("selected");
            $(obj).addClass("selected");

            ////根据选中的行获取子表数据
            //GetSonData(row.ID);
        },
        onSearch: function (text) {
            if (text != "") {
                $("#tabData tbody tr td:not(.bs-checkbox)").each(function (i) {
                    var str = "<span class=\"bg-yellow\">" + text + "</span>";
                    var NewText = $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).text().replaceAll(text, str);
                    $("#tabData tbody tr td:not(.bs-checkbox)").eq(i).html(NewText);
                })
            }
            },
            onLoadSuccess: function (data) {
                setTimeout(function () {
                    $('[data-toggle="popover"]').popover();
                }, 1500);
            }
            });

            })

        function getName(arr, n, v) {
            for (var i = 0; i < arr.length; i++)
                if (arr[i][n] == v)
                    return arr[i]["Text"];
        }

        function approval(borrowId) {
            layer.open({
                type: 2,
                title: "借阅批示",
                content: ["/document/borrow/approval/" + borrowId, 'no'],
                area: ['520px', '500px']
            });
        }

        function borrow(docId) {
            layer.open({
                type: 2,
                title: "公文借阅",
                content: ["/document/borrow/borrow/" + docId, 'no'],
                area: ['520px', '400px']
            });
        }

        function reBorrow(borrowId) {
            layer.open({
                type: 2,
                title: "公文借阅",
                content: ["/document/borrow/reborrow/" + borrowId, 'no'],
                area: ['520px', '400px']
            });
        }

           function del(id) {
            layer.confirm('是否删除此收文？', {
                btn: ['确定', '取消'] //按钮
            }, function () {
                var url = '@Url.Action("DocumentDelete", "Receive", new { area = "Document" })\/' + id;
                $.get(url, function (result) {
                    $("#DocumentDataTable").bootstrapTable('refresh', { url: '/Receive/GetTableJsonResult'});
                    layer.msg('删除收文成功！',{ icon: 1,
                        time: 2000//2s后自动关闭
                    });
                });
            }, function () {

            });
        }
    </script>
}